home *** CD-ROM | disk | FTP | other *** search
- ;/* Execute me to compile with DICE V3.0
- dcc idcmphook.c -proto -mi -ms -mRR -lbgui
- quit
- */
- /*
- ** $RCSfile: idcmphook.c,v $
- ** Description: Simple demonstration of a IDCMP hook
- ** attached to a BGUI windowclass object.
- ** Copyright: (C) Copyright 1994 Jaba Development.
- ** (C) Copyright 1994 Jan van den Baard.
- ** All Rights Reserved.
- **
- ** $Author: jaba $
- ** $Revision: 1.2 $
- ** $Date: 1994/08/03 11:37:17 $
- **/
-
- #include <libraries/bgui.h>
- #include <libraries/bgui_macros.h>
- #include <libraries/gadtools.h>
-
- #include <clib/alib_protos.h>
-
- #include <proto/exec.h>
- #include <proto/bgui.h>
- #include <proto/intuition.h>
-
- #include <stdio.h>
- #include <stdlib.h>
-
- /*
- ** Library base pointer.
- ** NOTE: The intuition.library is opened by DICE
- ** it's auto-init code.
- **/
- struct Library *BGUIBase;
-
- /*
- ** Object ID.
- **/
- #define ID_QUIT 1
-
- /*
- ** "tick" counter for the hook.
- **/
- UBYTE Ticks = 0;
-
- /*
- ** Simple example of the hook code.
- **/
- #ifdef _DCC
- __geta4 VOID hookFunc( __A0 struct Hook *hook,
- __A2 Object *obj,
- __A1 struct IntuiMessage *imsg )
- #else
- __saveds __asm VOID hookFunc( register __a0 struct Hook *hook,
- register __a2 Object *obj,
- register __a1 struct IntuiMessage *imsg )
- #endif
- {
- struct Window *wptr = NULL;
-
- /*
- ** This hook is a simple IDCMP_INTUITICKS hook.
- ** More complex hooks can receive several message
- ** types depending on the setting of the
- ** WINDOW_IDCMPHookBits attribute.
- **
- ** Simply beep the screen
- ** every two seconds or so
- ** while the window is active.
- **/
- if ( Ticks == 20 ) {
- Ticks = 0;
- /*
- ** Only flash the screen on which
- ** the window is located.
- **/
- GetAttr( WINDOW_Window, obj, ( ULONG * )&wptr );
- if ( wptr )
- DisplayBeep( wptr->WScreen );
- }
- Ticks++;
- }
-
-
- /*
- ** The hook structure.
- **
- ** typedef unsigned long (*HOOKFUNC)();
- **/
- struct Hook idcmpHook = {
- NULL, NULL, (HOOKFUNC)hookFunc, NULL, NULL };
-
- int main( int argc, char *argv[] )
- {
- struct Window *window;
- Object *WO_Window, *GO_Quit;
- ULONG signal = 0, rc, tmp = 0;
- BOOL running = TRUE;
-
- /*
- ** Open the library.
- **/
- if ( BGUIBase = OpenLibrary( BGUINAME, BGUIVERSION )) {
- /*
- ** Create the window object.
- **/
- WO_Window = WindowObject,
- WINDOW_Title, "IDCMPHook Demo",
- WINDOW_SizeGadget, FALSE,
- WINDOW_IDCMP, IDCMP_INTUITICKS,
- WINDOW_IDCMPHookBits, IDCMP_INTUITICKS,
- WINDOW_IDCMPHook, &idcmpHook,
- WINDOW_MasterGroup,
- /*
- ** A simple vertical group
- ** containing a descriptive text
- ** and a "Quit" button.
- **/
- VGroupObject, HOffset( 4 ), VOffset( 4 ), Spacing( 4 ),
- StartMember, InfoFixed( NULL, "\33cThis small demo has a IDCMP-hook\n"
- "installed which will flash the\n"
- "display every two seconds while the\n"
- "window is active.", NULL, 4 ), EndMember,
- StartMember, GO_Quit = KeyButton( "_Quit", ID_QUIT ), EndMember,
- EndObject,
- EndObject;
-
- /*
- ** Object created OK?
- **/
- if ( WO_Window ) {
- /*
- ** Assign a key to the button.
- **/
- if ( GadgetKey( WO_Window, GO_Quit, "q" )) {
- /*
- ** try to open the window.
- **/
- if ( window = WindowOpen( WO_Window )) {
- /*
- ** Obtain it's wait mask.
- **/
- GetAttr( WINDOW_SigMask, WO_Window, &signal );
- /*
- ** Event loop...
- **/
- do {
- Wait( signal );
- /*
- ** Handle events.
- **/
- while (( rc = HandleEvent( WO_Window )) != WMHI_NOMORE ) {
- /*
- ** Evaluate return code.
- **/
- switch ( rc ) {
-
- case WMHI_CLOSEWINDOW:
- case ID_QUIT:
- puts( "bye bye" );
- running = FALSE;
- break;
- }
- }
- } while ( running );
- } else
- puts ( "Could not open the window" );
- } else
- puts( "Could not assign gadget key" );
- /*
- ** Disposing of the window object will
- ** also close the window if it is
- ** already opened and it will dispose of
- ** all objects attached to it.
- **/
- DisposeObject( WO_Window );
- } else
- puts( "Could not create the window object" );
- CloseLibrary( BGUIBase );
- } else
- puts( "Unable to open the bgui.library" );
-
- return( 0 );
- }
-
- #ifdef _DCC
- int wbmain( struct wbStartup *wbs )
- {
- return( main( 0, NULL ));
- }
- #endif
-
- /*
- * $Log: idcmphook.c,v $
- * Revision 1.2 1994/08/03 11:37:17 jaba
- * Switched from clib/ to proto/.
- *
- * Revision 1.1 1994/06/20 16:43:03 jaba
- * Initial revision
- *
- */
-